import java.util.Arrays;

public class Most_Sanjiao {

        public int triangleNumber(int[] nums) {
            Arrays.sort(nums);
            int ret = 0;
            int n = nums.length;
            for(int i = n-1;i>=2;i--){
                int left = 0,right = i-1;
                while(left<right){
                    if(nums[left]+nums[right]<=nums[i]){
                        left++;
                    }
                    else{
                        ret=ret+right-left;
                        right--;

                    }
                }
            }
            return ret;
        }

}
